﻿CREATE TABLE [dbo].[Despiece] (
    [IdProducto] INT                 NOT NULL,
    [IdParte]    INT                 NOT NULL,
    [Jerarquia]  [sys].[hierarchyid] NOT NULL,
    [Nivel]      AS                  ([Jerarquia].[GetLevel]()),
    [Cantidad]   INT                 NULL,
    CONSTRAINT [PK_Despiece] PRIMARY KEY CLUSTERED ([IdProducto] ASC, [IdParte] ASC, [Jerarquia] ASC),
    CONSTRAINT [FK_Despiece_Parte] FOREIGN KEY ([IdParte]) REFERENCES [dbo].[Parte] ([IdParte]),
    CONSTRAINT [FK_Despiece_Producto] FOREIGN KEY ([IdProducto]) REFERENCES [dbo].[Producto] ([IdProducto])
);



